package com.sk.sourcecircle.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.sk.sourcecircle.R;
import com.sk.sourcecircle.activity.home.activity.DetailsOfConsultationActivity;
import com.sk.sourcecircle.activity.home.activity.EventDetailsActivity;
import com.sk.sourcecircle.entity.HomeBannerBean;

import java.util.List;

/**
 * Created by sk on 2017/11/23.
 */

public class BannerAdapter extends StaticPagerAdapter {

    private List<HomeBannerBean.DataBean> bannerEntities;
    private Context context;

    public BannerAdapter(List<HomeBannerBean.DataBean> bannerEntities, Context context) {
        this.bannerEntities = bannerEntities;
        this.context = context;
    }

    @Override
    public View getView(ViewGroup container, final int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_banner,null);
        ImageView item_bg = view.findViewById(R.id.item_bg);
        TextView tv_title = view.findViewById(R.id.tv_title);
        Glide.with(context).load(bannerEntities.get(position).getHead_image()).into(item_bg);
        tv_title.setText(bannerEntities.get(position).getTitle());
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(bannerEntities.get(position).getRec_type() == 0){
                    Intent intent = new Intent(context, EventDetailsActivity.class);
                    intent.putExtra("id",bannerEntities.get(position).getRec_id());
                    context.startActivity(intent);

                }else if(bannerEntities.get(position).getRec_type() == 1){
                    Intent intent = new Intent(context, DetailsOfConsultationActivity.class);
                    intent.putExtra("id",bannerEntities.get(position).getRec_id());
                    context.startActivity(intent);
                }
            }
        });
        return view;
    }

    @Override
    public int getCount() {
        return bannerEntities.size();
    }

}
